<template>
  <div class="cost-budget-page">
    <!-- 预算概览卡片 -->
    <el-row :gutter="20" class="overview-cards">
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="overview-card">
          <div class="card-content">
            <div class="card-icon total-budget">
              <el-icon size="24"><Wallet /></el-icon>
            </div>
            <div class="card-info">
              <div class="card-value">¥{{ formatNumber(budgetOverview.totalBudget) }}</div>
              <div class="card-label">总预算</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="overview-card">
          <div class="card-content">
            <div class="card-icon actual-cost">
              <el-icon size="24"><Money /></el-icon>
            </div>
            <div class="card-info">
              <div class="card-value">¥{{ formatNumber(budgetOverview.actualCost) }}</div>
              <div class="card-label">实际成本</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="overview-card">
          <div class="card-content">
            <div class="card-icon variance">
              <el-icon size="24"><TrendCharts /></el-icon>
            </div>
            <div class="card-info">
              <div class="card-value">¥{{ formatNumber(budgetOverview.variance) }}</div>
              <div class="card-label">预算差异</div>
              <div :class="['card-trend', budgetOverview.variance > 0 ? 'favorable' : 'unfavorable']">
                {{ budgetOverview.variance > 0 ? '节约' : '超支' }}
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="12" :md="6">
        <el-card class="overview-card">
          <div class="card-content">
            <div class="card-icon execution-rate">
              <el-icon size="24"><DataAnalysis /></el-icon>
            </div>
            <div class="card-info">
              <div class="card-value">{{ budgetOverview.executionRate }}%</div>
              <div class="card-label">预算执行率</div>
              <el-progress 
                :percentage="budgetOverview.executionRate" 
                :color="getProgressColor(budgetOverview.executionRate)"
                :show-text="false"
                style="margin-top: 8px"
              />
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 预算管理主区域 -->
    <el-card>
      <template #header>
        <div class="page-header">
          <h3>成本预算管理</h3>
          <div class="header-actions">
            <el-button type="primary" @click="showAddDialog">
              <el-icon><Plus /></el-icon>
              新建预算
            </el-button>
            <el-button type="success" @click="handleBatchImport">
              <el-icon><Upload /></el-icon>
              批量导入
            </el-button>
            <el-button @click="handleExport">
              <el-icon><Download /></el-icon>
              导出
            </el-button>
          </div>
        </div>
      </template>

      <!-- 搜索区域 -->
      <div class="search-area">
        <el-form :model="searchForm" inline>
          <el-form-item label="预算年度">
            <el-date-picker
              v-model="searchForm.year"
              type="year"
              placeholder="请选择年度"
              format="YYYY"
              value-format="YYYY"
              clearable
            />
          </el-form-item>
          <el-form-item label="部门">
            <el-select v-model="searchForm.department" placeholder="请选择部门" clearable>
              <el-option label="生产部" value="生产部" />
              <el-option label="销售部" value="销售部" />
              <el-option label="研发部" value="研发部" />
              <el-option label="行政部" value="行政部" />
            </el-select>
          </el-form-item>
          <el-form-item label="预算类型">
            <el-select v-model="searchForm.budgetType" placeholder="请选择预算类型" clearable>
              <el-option label="材料成本预算" value="材料成本" />
              <el-option label="人工成本预算" value="人工成本" />
              <el-option label="制造费用预算" value="制造费用" />
              <el-option label="管理费用预算" value="管理费用" />
            </el-select>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
              <el-option label="草稿" value="草稿" />
              <el-option label="待审核" value="待审核" />
              <el-option label="已批准" value="已批准" />
              <el-option label="执行中" value="执行中" />
              <el-option label="已完成" value="已完成" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSearch">
              <el-icon><Search /></el-icon>
              搜索
            </el-button>
            <el-button @click="handleReset">
              <el-icon><Refresh /></el-icon>
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>

      <!-- 表格区域 -->
      <el-table :data="tableData" v-loading="loading" stripe>
        <el-table-column type="selection" width="55" />
        <el-table-column prop="budgetNo" label="预算编号" width="150" fixed />
        <el-table-column prop="budgetName" label="预算名称" width="200" />
        <el-table-column prop="year" label="预算年度" width="100" />
        <el-table-column prop="department" label="部门" width="120" />
        <el-table-column prop="budgetType" label="预算类型" width="130">
          <template #default="{ row }">
            <el-tag :type="getBudgetTypeTag(row.budgetType)">
              {{ row.budgetType }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="预算金额" width="130" align="right">
          <template #default="{ row }">
            <span class="budget-amount">¥{{ formatNumber(row.budgetAmount) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际金额" width="130" align="right">
          <template #default="{ row }">
            <span class="actual-amount">¥{{ formatNumber(row.actualAmount) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="差异" width="130" align="right">
          <template #default="{ row }">
            <span :class="row.variance >= 0 ? 'variance-favorable' : 'variance-unfavorable'">
              {{ row.variance >= 0 ? '+' : '' }}¥{{ formatNumber(Math.abs(row.variance)) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="执行率" width="150">
          <template #default="{ row }">
            <div class="execution-rate">
              <span>{{ row.executionRate }}%</span>
              <el-progress 
                :percentage="row.executionRate" 
                :color="getProgressColor(row.executionRate)"
                :show-text="false"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template #default="{ row }">
            <el-tag :type="getStatusTag(row.status)">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" width="120" />
        <el-table-column label="操作" width="250" fixed="right">
          <template #default="{ row }">
            <el-button type="primary" size="small" @click="handleView(row)">
              查看
            </el-button>
            <el-button 
              v-if="row.status === '草稿'" 
              type="success" 
              size="small" 
              @click="handleEdit(row)"
            >
              编辑
            </el-button>
            <el-button 
              v-if="row.status === '待审核'" 
              type="warning" 
              size="small" 
              @click="handleApprove(row)"
            >
              审批
            </el-button>
            <el-button 
              type="danger" 
              size="small" 
              @click="handleDelete(row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="pagination.currentPage"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 预算对比图表 -->
    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :xs="24" :md="12">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>预算执行情况对比</span>
              <el-tag type="info">柱状图</el-tag>
            </div>
          </template>
          <div ref="budgetCompareChart" style="width: 100%; height: 400px"></div>
        </el-card>
      </el-col>
      <el-col :xs="24" :md="12">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>预算执行进度</span>
              <el-tag type="success">进度图</el-tag>
            </div>
          </template>
          <div class="budget-progress-list">
            <div v-for="item in progressData" :key="item.name" class="progress-item">
              <div class="progress-header">
                <span class="progress-name">{{ item.name }}</span>
                <span class="progress-value">{{ item.percentage }}%</span>
              </div>
              <el-progress 
                :percentage="item.percentage" 
                :color="getProgressColor(item.percentage)"
              />
              <div class="progress-detail">
                <span>预算: ¥{{ formatNumber(item.budget) }}</span>
                <span>实际: ¥{{ formatNumber(item.actual) }}</span>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 新建/编辑预算对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="dialogTitle"
      width="800px"
      @close="handleDialogClose"
    >
      <el-form
        ref="formRef"
        :model="form"
        :rules="formRules"
        label-width="120px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="预算名称" prop="budgetName">
              <el-input v-model="form.budgetName" placeholder="请输入预算名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预算年度" prop="year">
              <el-date-picker
                v-model="form.year"
                type="year"
                placeholder="请选择年度"
                style="width: 100%"
                format="YYYY"
                value-format="YYYY"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门" prop="department">
              <el-select v-model="form.department" placeholder="请选择部门" style="width: 100%">
                <el-option label="生产部" value="生产部" />
                <el-option label="销售部" value="销售部" />
                <el-option label="研发部" value="研发部" />
                <el-option label="行政部" value="行政部" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预算类型" prop="budgetType">
              <el-select v-model="form.budgetType" placeholder="请选择预算类型" style="width: 100%">
                <el-option label="材料成本" value="材料成本" />
                <el-option label="人工成本" value="人工成本" />
                <el-option label="制造费用" value="制造费用" />
                <el-option label="管理费用" value="管理费用" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="预算金额" prop="budgetAmount">
          <el-input-number 
            v-model="form.budgetAmount" 
            :min="0" 
            :precision="2"
            style="width: 100%"
            placeholder="请输入预算金额"
          >
            <template #prefix>¥</template>
          </el-input-number>
        </el-form-item>

        <el-divider content-position="left">月度预算分配</el-divider>

        <el-form-item label="分配方式">
          <el-radio-group v-model="form.allocationType" @change="handleAllocationChange">
            <el-radio label="average">平均分配</el-radio>
            <el-radio label="custom">自定义分配</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="月度明细">
          <el-table :data="form.monthlyBudgets" border>
            <el-table-column prop="month" label="月份" width="80" />
            <el-table-column label="预算金额" width="200">
              <template #default="{ row }">
                <el-input-number 
                  v-model="row.amount" 
                  :min="0" 
                  :precision="2"
                  size="small"
                  :disabled="form.allocationType === 'average'"
                  style="width: 100%"
                />
              </template>
            </el-table-column>
            <el-table-column label="占比">
              <template #default="{ row }">
                {{ calculatePercentage(row.amount) }}%
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="备注">
          <el-input 
            v-model="form.remark" 
            type="textarea" 
            :rows="3"
            placeholder="请输入备注信息" 
          />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button @click="handleSaveDraft" :loading="submitLoading">
          保存草稿
        </el-button>
        <el-button type="primary" @click="handleSubmit" :loading="submitLoading">
          提交审核
        </el-button>
      </template>
    </el-dialog>

    <!-- 预算详情对话框 -->
    <el-dialog
      v-model="detailDialogVisible"
      title="预算详情"
      width="900px"
    >
      <el-descriptions :column="2" border>
        <el-descriptions-item label="预算编号">{{ currentDetail.budgetNo }}</el-descriptions-item>
        <el-descriptions-item label="预算名称">{{ currentDetail.budgetName }}</el-descriptions-item>
        <el-descriptions-item label="预算年度">{{ currentDetail.year }}</el-descriptions-item>
        <el-descriptions-item label="部门">{{ currentDetail.department }}</el-descriptions-item>
        <el-descriptions-item label="预算类型">
          <el-tag :type="getBudgetTypeTag(currentDetail.budgetType)">
            {{ currentDetail.budgetType }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="状态">
          <el-tag :type="getStatusTag(currentDetail.status)">
            {{ currentDetail.status }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="预算金额">
          <span class="budget-amount">¥{{ formatNumber(currentDetail.budgetAmount) }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="实际金额">
          <span class="actual-amount">¥{{ formatNumber(currentDetail.actualAmount) }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="差异">
          <span :class="currentDetail.variance >= 0 ? 'variance-favorable' : 'variance-unfavorable'">
            {{ currentDetail.variance >= 0 ? '+' : '' }}¥{{ formatNumber(Math.abs(currentDetail.variance)) }}
          </span>
        </el-descriptions-item>
        <el-descriptions-item label="执行率">
          <div class="execution-rate">
            <span>{{ currentDetail.executionRate }}%</span>
            <el-progress 
              :percentage="currentDetail.executionRate" 
              :color="getProgressColor(currentDetail.executionRate)"
            />
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="创建日期">{{ currentDetail.createDate }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ currentDetail.remark || '无' }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import * as echarts from 'echarts'

// 响应式数据
const loading = ref(false)
const dialogVisible = ref(false)
const detailDialogVisible = ref(false)
const submitLoading = ref(false)
const formRef = ref()
const dialogTitle = ref('新建预算')
const budgetCompareChart = ref()

// 预算概览数据
const budgetOverview = reactive({
  totalBudget: 5000000,
  actualCost: 4350000,
  variance: 650000,
  executionRate: 87
})

// 搜索表单
const searchForm = reactive({
  year: '',
  department: '',
  budgetType: '',
  status: ''
})

// 表单数据
const form = reactive({
  budgetName: '',
  year: '',
  department: '',
  budgetType: '',
  budgetAmount: 0,
  allocationType: 'average',
  monthlyBudgets: Array.from({ length: 12 }, (_, i) => ({
    month: `${i + 1}月`,
    amount: 0
  })),
  remark: ''
})

// 表单验证规则
const formRules = {
  budgetName: [
    { required: true, message: '请输入预算名称', trigger: 'blur' }
  ],
  year: [
    { required: true, message: '请选择预算年度', trigger: 'change' }
  ],
  department: [
    { required: true, message: '请选择部门', trigger: 'change' }
  ],
  budgetType: [
    { required: true, message: '请选择预算类型', trigger: 'change' }
  ],
  budgetAmount: [
    { required: true, message: '请输入预算金额', trigger: 'blur' }
  ]
}

// 分页数据
const pagination = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 0
})

// 当前详情
const currentDetail = reactive({})

// 表格数据
const tableData = ref([
  {
    id: 1,
    budgetNo: 'BG20240001',
    budgetName: '2024年生产部材料成本预算',
    year: '2024',
    department: '生产部',
    budgetType: '材料成本',
    budgetAmount: 1200000,
    actualAmount: 1050000,
    variance: 150000,
    executionRate: 87.5,
    status: '执行中',
    createDate: '2024-01-01',
    remark: '第一季度生产预算'
  },
  {
    id: 2,
    budgetNo: 'BG20240002',
    budgetName: '2024年生产部人工成本预算',
    year: '2024',
    department: '生产部',
    budgetType: '人工成本',
    budgetAmount: 800000,
    actualAmount: 720000,
    variance: 80000,
    executionRate: 90,
    status: '执行中',
    createDate: '2024-01-01',
    remark: ''
  },
  {
    id: 3,
    budgetNo: 'BG20240003',
    budgetName: '2024年销售部管理费用预算',
    year: '2024',
    department: '销售部',
    budgetType: '管理费用',
    budgetAmount: 500000,
    actualAmount: 480000,
    variance: 20000,
    executionRate: 96,
    status: '执行中',
    createDate: '2024-01-01',
    remark: ''
  },
  {
    id: 4,
    budgetNo: 'BG20240004',
    budgetName: '2024年研发部制造费用预算',
    year: '2024',
    department: '研发部',
    budgetType: '制造费用',
    budgetAmount: 600000,
    actualAmount: 550000,
    variance: 50000,
    executionRate: 91.7,
    status: '待审核',
    createDate: '2024-01-10',
    remark: ''
  }
])

// 进度数据
const progressData = ref([
  { name: '材料成本预算', budget: 1200000, actual: 1050000, percentage: 87.5 },
  { name: '人工成本预算', budget: 800000, actual: 720000, percentage: 90 },
  { name: '制造费用预算', budget: 600000, actual: 550000, percentage: 91.7 },
  { name: '管理费用预算', budget: 500000, actual: 480000, percentage: 96 }
])

// 方法
const formatNumber = (value) => {
  if (typeof value === 'number') {
    return value.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
  }
  return value
}

const getBudgetTypeTag = (type) => {
  const typeMap = {
    '材料成本': 'primary',
    '人工成本': 'success',
    '制造费用': 'warning',
    '管理费用': 'info'
  }
  return typeMap[type] || 'info'
}

const getStatusTag = (status) => {
  const statusMap = {
    '草稿': 'info',
    '待审核': 'warning',
    '已批准': 'success',
    '执行中': 'primary',
    '已完成': ''
  }
  return statusMap[status] || 'info'
}

const getProgressColor = (percentage) => {
  if (percentage < 60) return '#67c23a'
  if (percentage < 85) return '#e6a23c'
  if (percentage < 100) return '#f56c6c'
  return '#909399'
}

const calculatePercentage = (amount) => {
  if (form.budgetAmount === 0) return 0
  return ((amount / form.budgetAmount) * 100).toFixed(1)
}

const handleAllocationChange = (type) => {
  if (type === 'average') {
    const avgAmount = form.budgetAmount / 12
    form.monthlyBudgets.forEach(item => {
      item.amount = avgAmount
    })
  }
}

const initBudgetCompareChart = () => {
  const chart = echarts.init(budgetCompareChart.value)
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    legend: {
      data: ['预算金额', '实际金额'],
      bottom: 0
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '12%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: ['材料成本', '人工成本', '制造费用', '管理费用']
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        formatter: '¥{value}'
      }
    },
    series: [
      {
        name: '预算金额',
        type: 'bar',
        data: [1200000, 800000, 600000, 500000],
        itemStyle: { color: '#5470c6' }
      },
      {
        name: '实际金额',
        type: 'bar',
        data: [1050000, 720000, 550000, 480000],
        itemStyle: { color: '#91cc75' }
      }
    ]
  }
  chart.setOption(option)
  
  window.addEventListener('resize', () => {
    chart.resize()
  })
}

const loadData = () => {
  loading.value = true
  setTimeout(() => {
    pagination.total = tableData.value.length
    loading.value = false
  }, 500)
}

const handleSearch = () => {
  pagination.currentPage = 1
  loadData()
}

const handleReset = () => {
  Object.assign(searchForm, {
    year: '',
    department: '',
    budgetType: '',
    status: ''
  })
  handleSearch()
}

const showAddDialog = () => {
  dialogTitle.value = '新建预算'
  dialogVisible.value = true
  resetForm()
}

const handleView = (row) => {
  Object.assign(currentDetail, row)
  detailDialogVisible.value = true
}

const handleEdit = (row) => {
  dialogTitle.value = '编辑预算'
  Object.assign(form, row)
  dialogVisible.value = true
}

const handleApprove = async (row) => {
  try {
    await ElMessageBox.confirm('确定要批准该预算吗？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    const index = tableData.value.findIndex(item => item.id === row.id)
    if (index > -1) {
      tableData.value[index].status = '已批准'
      ElMessage.success('批准成功')
      loadData()
    }
  } catch {
    // 用户取消操作
  }
}

const handleDelete = async (row) => {
  try {
    await ElMessageBox.confirm('确定要删除该预算吗？此操作不可恢复！', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    const index = tableData.value.findIndex(item => item.id === row.id)
    if (index > -1) {
      tableData.value.splice(index, 1)
      ElMessage.success('删除成功')
      loadData()
    }
  } catch {
    // 用户取消操作
  }
}

const handleBatchImport = () => {
  ElMessage.info('批量导入功能开发中')
}

const handleExport = () => {
  ElMessage.success('导出成功')
}

const handleSaveDraft = async () => {
  if (!formRef.value) return

  try {
    await formRef.value.validate()
    submitLoading.value = true

    await new Promise(resolve => setTimeout(resolve, 1000))

    ElMessage.success('草稿保存成功')
    dialogVisible.value = false
    loadData()
  } catch (error) {
    console.error('表单验证失败:', error)
  } finally {
    submitLoading.value = false
  }
}

const handleSubmit = async () => {
  if (!formRef.value) return

  try {
    await formRef.value.validate()
    submitLoading.value = true

    await new Promise(resolve => setTimeout(resolve, 1000))

    const newRecord = {
      id: Date.now(),
      budgetNo: `BG${new Date().getFullYear()}${String(tableData.value.length + 1).padStart(4, '0')}`,
      budgetName: form.budgetName,
      year: form.year,
      department: form.department,
      budgetType: form.budgetType,
      budgetAmount: form.budgetAmount,
      actualAmount: 0,
      variance: form.budgetAmount,
      executionRate: 0,
      status: '待审核',
      createDate: new Date().toISOString().split('T')[0],
      remark: form.remark
    }
    
    tableData.value.unshift(newRecord)
    ElMessage.success('预算提交成功')
    dialogVisible.value = false
    loadData()
  } catch (error) {
    console.error('表单验证失败:', error)
  } finally {
    submitLoading.value = false
  }
}

const handleDialogClose = () => {
  resetForm()
}

const resetForm = () => {
  Object.assign(form, {
    budgetName: '',
    year: '',
    department: '',
    budgetType: '',
    budgetAmount: 0,
    allocationType: 'average',
    monthlyBudgets: Array.from({ length: 12 }, (_, i) => ({
      month: `${i + 1}月`,
      amount: 0
    })),
    remark: ''
  })
  formRef.value?.clearValidate()
}

const handleSizeChange = (size) => {
  pagination.pageSize = size
  loadData()
}

const handleCurrentChange = (page) => {
  pagination.currentPage = page
  loadData()
}

// 生命周期
onMounted(() => {
  loadData()
  nextTick(() => {
    initBudgetCompareChart()
  })
})
</script>

<style scoped>
.cost-budget-page {
  padding: 0;
}

.overview-cards {
  margin-bottom: 20px;
}

.overview-card {
  border: none;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.card-content {
  display: flex;
  align-items: center;
}

.card-icon {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  color: white;
}

.card-icon.total-budget {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.card-icon.actual-cost {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.card-icon.variance {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.card-icon.execution-rate {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.card-info {
  flex: 1;
}

.card-value {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.card-label {
  font-size: 14px;
  color: #909399;
  margin-bottom: 4px;
}

.card-trend {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
}

.card-trend.favorable {
  background: #e1f3d8;
  color: #67c23a;
}

.card-trend.unfavorable {
  background: #fde2e2;
  color: #f56c6c;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page-header h3 {
  margin: 0;
  color: #303133;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-area {
  margin-bottom: 20px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 4px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}

.budget-amount {
  color: #409eff;
  font-weight: 600;
}

.actual-amount {
  color: #67c23a;
  font-weight: 600;
}

.variance-favorable {
  color: #67c23a;
  font-weight: 600;
}

.variance-unfavorable {
  color: #f56c6c;
  font-weight: 600;
}

.execution-rate {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.execution-rate span {
  font-weight: 600;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.budget-progress-list {
  padding: 20px;
}

.progress-item {
  margin-bottom: 24px;
}

.progress-item:last-child {
  margin-bottom: 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.progress-name {
  font-weight: 600;
  color: #303133;
}

.progress-value {
  font-weight: 600;
  color: #409eff;
}

.progress-detail {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: #909399;
}
</style>
